<?php

namespace app\controller\tools;


use app\service\Dir;
use think\facade\Config;

class Rename extends Base
{
	
	// 批量重命名
	// 尤其是图片批量重命名、模板文件批量重命名
	public function batch()
	{
		$path  = 'D:\phpsite\light2025\blade\frontend\news';
		$cline = '<br>';
		$dir   = new Dir();
		// 读取文件 并 重命名
		$files = $dir->read($path, false);
		foreach($files as $file){
			// 获取文件名的拓展名
			$ext = pathinfo($file, PATHINFO_EXTENSION);
			if($ext != 'html'){
				continue;
			}
			
			// 修改文件名后缀
			$new = str_replace('.html', '.blade.php', $file);
			rename($file, $new);
		}
		
		echo 'ok';
	}
	
	// 生成文件
	// http://template/tools/rename/make
	public function make()
	{
		$number = 2;
		$name   = "article,question,event,vote,star";
		
		
		// 将内容写入文件，如果文件不存在则创建
		$names   = explode(',', $name);
		$_path   = $this->app->getRootPath().'/'.Config::get('view.view_dir_name').'/frontend/bootstrap/make/';
		$content = "\n";
		for($ii = 1; $ii <= $number; $ii++){
			foreach($names as $_name){
				$_file = $_path.$_name.$ii.'.blade.php';
				file_put_contents($_file, $content);
			}
		}
		echo 'ok';
	}
	
}

